package net.hn.hnms.biz.safety.trinity.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import net.hn.hnms.biz.api.feign.model.DataStateVo;
import net.hn.hnms.biz.common.jpa.utils.ResponsePage;
import net.hn.hnms.biz.safety.trinity.entity.RiskRecordDto;
import net.hn.hnms.biz.safety.trinity.entity.RiskRecordVo;
import net.hn.hnms.biz.safety.trinity.service.RiskControlService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.excel.utils.ExcelUtil;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 智呈物联 pan'sx
 * 2022/7/26 10:41
 * 1.0 version
 */
@RestController
@RequestMapping("manage/riskRecord")
@Api(value = "安全风险台账控制器", tags = {"安全风险台账"})
public class RiskRecordController {
    RiskControlService riskControlService;

    @Autowired
    public void setRiskControlService(RiskControlService riskControlService) {
        this.riskControlService = riskControlService;
    }

    @GetMapping("page")
    @ApiOperation("风险台账 分页查询")
    @AutoSetMineCode
    public R<ResponsePage<RiskRecordVo>> page(PageQuery pageQuery, RiskRecordDto riskRecordDto,String mineCode) {
        //todo
        return R.ok(riskControlService.page(pageQuery,riskRecordDto,mineCode));
    }

    @GetMapping(value = "export", produces = "application/octet-stream")
    @ApiOperation(value = "导出数据")
    @AutoSetMineCode
    public void export(HttpServletResponse response,PageQuery pageQuery, RiskRecordDto riskRecordDto,String mineCode) throws IOException {
        // todo
        String fileName = "风险台账";

        List<RiskRecordVo> list = riskControlService.page(pageQuery,riskRecordDto,mineCode).getPageData();
//        DictData dictData = new DictData();

//        Map<String,String> riskMajor = dictData.dictToMap("risk_danger_violation_major");
//
//        Map<String,String> riskClass = dictData.dictToMap("risk_danger_class");

//        for (RiskRecordVo riskRecordVo:list){
//            String riskMajorValue = riskMajor.get(riskRecordVo.getMajor());
//            if (riskMajorValue!=null){
//                riskRecordVo.setMajor(riskMajorValue);
//            }
//            String riskClassValue = riskClass.get(riskRecordVo.getType());
//            if (riskClassValue!=null){
//                riskRecordVo.setType(riskClassValue);
//            }
//        }

        ExcelUtil.exportExcel(list,fileName, RiskRecordVo.class,response);
    }
    @GetMapping("maxTime")
    @ApiOperation("数据最新时间")
    public R<List<DataStateVo>> getMaxTime(String mineCode, String companyCode){
        return R.ok(riskControlService.getMaxTime( mineCode,companyCode));
    }
}
